/*
** printf.c for printf in /home/boulah_m/printf
**
** Made by moustafa boulahia
** Login   <boulah_m@epitech.net>
**
** Started on  Mon Nov 14 08:42:56 2011 moustafa boulahia
** Last update Mon Feb  6 10:40:56 2012 moustafa boulahia
*/
#include <stdarg.h>
#include <stdlib.h>
#include "my.h"

int	my_printf(char *str, ...)
{
  va_list	ap;

  if (str != NULL)
    {
      va_start(ap, str);
      while (*str != '\0')
	{
	  if (*str != '%')
	    {
	      my_putchar(*str);
	      str = str + 1;
	    }
	  else
	    {
	      str = str + 1;
	      while (*str == ' ')
		{
		  str = str + 1;
		}
	      if (*str == 's')
		{
		  my_putstr(va_arg(ap, char *));
		  str = str + 1;
		}
	      else if (*str == 'p')
		{
		  my_putnbr_base(va_arg(ap, int), "0123456789ABCDEF");
		  str = str + 1;
		}
	      else if (*str == 'd')
		{
		  my_putnbr(va_arg(ap, int));
		  str = str + 1;
		}
	      else if (*str == 'b')
		{
		  my_putnbr_base(va_arg(ap, int), "01");
		  str = str + 1;
		}
	      else if (*str == 'c')
		{
		  my_putchar(va_arg(ap, int));
		  str = str + 1;
		}
	      else if (*str == '%')
		{
		  my_putchar('%');
		  str = str + 1;
		}
	      else if (*str == 'S')
		{
		  octal(va_arg(ap, char *));
		  str = str + 1;
		}
	      else
		{
		  my_putstr("ERROR IVALIDE PARAMETRES\n");
		  return (0);
		}
	    }
	}
      va_end(ap);
    }
  return (0);
}
